package com.tadpole.music.holder.me;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.me.MoNiErrorBean;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.NoDoubleClickListener;

/**
 * Created By 孙岩
 * on 2020/12/26
 */
public class WorkV2ViewHolder extends BaseViewHolder {
    private View itemView;
    private Activity activity;
    private BaseAdapter.OnItemClickListener onItemClickListener;
    private MoNiErrorBean.DataBean bean;
    //名称
    private TextView tvName;
    //底部背景
    private RelativeLayout rlBg;
    //学生还未练习
    private TextView tvNo;
    //正确率
    private TextView tvZhengQueLv;
    //错题数量
    private TextView tvShuLiang;
    //角标
    private ImageView ivImage;
    //状态
    private ImageView ivState;
    public WorkV2ViewHolder(Activity activity,View itemView, BaseAdapter.OnItemClickListener onItemClickListener, MoNiErrorBean.DataBean bean) {
        super(itemView);
        this.activity = activity;
        this.bean = bean;
        this.itemView = itemView;
        this.onItemClickListener = onItemClickListener;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void init(final int position) {
        tvName = itemView.findViewById(R.id.tvName);
        rlBg = itemView.findViewById(R.id.rlBg);
        tvNo = itemView.findViewById(R.id.tvNo);
        tvZhengQueLv = itemView.findViewById(R.id.tvZhengQueLv);
        tvShuLiang = itemView.findViewById(R.id.tvShuLiang);
        ivImage = itemView.findViewById(R.id.ivImage);
        ivState = itemView.findViewById(R.id.ivState);


        tvName.setText(bean.getMonth_class_static().get(position).getName());

        if(bean.getMonth_class_static().get(position).getRate().equals("0.00")){
            tvName.setTextColor(activity.getResources().getColor(R.color.color_55));
            rlBg.setBackgroundResource(R.drawable.bg_gray_no);
            tvZhengQueLv.setVisibility(View.GONE);
            tvShuLiang.setVisibility(View.GONE);
            tvNo.setVisibility(View.VISIBLE);
            tvNo.setText("学生还未练习");
            ivImage.setVisibility(View.GONE);
            ivState.setVisibility(View.GONE);
        }else{
            tvName.setTextColor(activity.getResources().getColor(R.color.color_33));
            rlBg.setBackgroundResource(R.drawable.bg_gren);
            tvZhengQueLv.setVisibility(View.VISIBLE);
            tvShuLiang.setVisibility(View.VISIBLE);
            tvNo.setVisibility(View.GONE);
            tvZhengQueLv.setText("正确率"+((Double.parseDouble(bean.getMonth_class_static().get(position).getRate()))*100)+"%");
            tvShuLiang.setText("错题"+bean.getMonth_class_static().get(position).getErr_no()+"道");
            ivImage.setVisibility(View.VISIBLE);
            ivState.setVisibility(View.VISIBLE);
            if((Double.parseDouble(bean.getMonth_class_static().get(position).getRate())*100)>=85){
                ivState.setImageResource(R.mipmap.youxiu);
            }else if((Double.parseDouble(bean.getMonth_class_static().get(position).getRate())*100)<85&&(Double.parseDouble(bean.getMonth_class_static().get(position).getRate())*100)>=60){
                ivState.setImageResource(R.mipmap.lianghao);
            }else{
                ivState.setImageResource(R.mipmap.jiaocha);
            }

            itemView.setOnClickListener(new NoDoubleClickListener() {
                @Override
                protected void onNoDoubleClick(View v) {
                    onItemClickListener.onItemClick(itemView, position);
                }
            });
        }
    }
}
